import { defineStore } from 'pinia';

interface UserInfo {
    name:string
    age:number
    token:string
}
// 右边是调了一个函数 返回 一个仓库
export const useUserInfoStore = defineStore('userInfo', {
    state: () => {
        return {
            userInfo:{
                name:"wfs1",
                age:20,
                token:"tokens1"
            }
        };
    },
    getters:{
        name: state => {
            return state.userInfo.name
        },
        token: state => {
            return state.userInfo.token
        },
        age:state => {
            return state.userInfo.age
        },
    },
    actions: {
        setUserInfo(val:UserInfo) {
            console.log("val",val)
            this.userInfo = val;
        },
        resetUserInfo(val:any) {
            this.userInfo = {
                name:"wfs1",
                age:20,
                token:"tokens1"
            };
        }
    }
});
